package com.lagou.mr.speakBean;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

// 1 实现writable接口
public class SpeakBean implements Writable {
    private long selfDuration;
    private long thirdParDuration;
    private long sumDuration;

    public SpeakBean() {
    }

    public SpeakBean(long selfDuration, long thirdParDuration) {
        this.selfDuration = selfDuration;
        this.thirdParDuration = thirdParDuration;
        this.sumDuration = selfDuration + thirdParDuration;
    }

    @Override
    public String toString() {
        return selfDuration +
                "\t" + thirdParDuration +
                "\t" + sumDuration ;
    }

    public long getSelfDuration() {
        return selfDuration;
    }

    public void setSelfDuration(long selfDuration) {
        this.selfDuration = selfDuration;
    }

    public long getThirdParDuration() {
        return thirdParDuration;
    }

    public void setThirdParDuration(long thirdParDuration) {
        this.thirdParDuration = thirdParDuration;
    }

    public long getSumDuration() {
        return sumDuration;
    }

    public void setSumDuration(long sumDuration) {
        this.sumDuration = sumDuration;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(selfDuration);
        out.writeLong(thirdParDuration);
        out.writeLong(sumDuration);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.selfDuration = in.readLong();
        this.thirdParDuration = in.readLong();
        this.sumDuration = in.readLong();
    }


    public void set(long selfDuration, long thirdParDuration) {
        this.selfDuration = selfDuration;
        this.thirdParDuration = thirdParDuration;
        this.sumDuration = selfDuration + thirdParDuration;
    }
}
